//
//  AppDelegate+LCAddAD.m
//  lgbt
//
//  Created by jiukuyinyue on 2017/11/30.
//  Copyright © 2017年 lgbt. All rights reserved.
//

#import "AppDelegate+LCAddAD.h"
#import <objc/runtime.h>

static void *zViewKey = &zViewKey;
static void *fViewKey = &fViewKey;
static void *rViewKey = &rViewKey;

@implementation AppDelegate (LCAddAD)

///启动广告
- (void)setupStartLoadingAD {
    self.fView =[[UIImageView alloc]init];//初始化self.fView
    self.fView.image=[UIImage imageNamed:@"title"];//图片f.png 到self.fView
    [self.fView sizeToFit];
    self.fView.center = self.window.center;
//    self.zView=[[UIImageView alloc]init];//初始化self.zView
//    self.zView.image=[UIImage imageNamed:@"title"];//图片z.png 到self.zView
//    [self.zView sizeToFit];
//    self.zView.center = self.window.center;
    self.rView=[[UIView alloc]initWithFrame:self.window.frame];//初始化self.rView
    
    self.rView.backgroundColor = [UIColor whiteColor];
    [self.rView addSubview:self.fView];//add 到self.rView
//    [self.rView addSubview:self.zView];//add 到self.rView
    
    
    [self.window addSubview:self.rView];//add 到window
    
    [self performSelector:@selector(TheAnimation) withObject:nil afterDelay:0.0001];
    //1秒后执行TheAnimation

}

- (void)TheAnimation{
    
//    CATransition *animation = [CATransition animation];
//    animation.delegate = self;
//    animation.duration = 0.7 ;  // 动画持续时间(秒)
//#pragma clang diagnostic ignored "-Wnon-literal-null-conversion"
//    animation.timingFunction = UIViewAnimationCurveEaseInOut;
//    animation.type = kCATransitionFade;//淡入淡出效果
    NSUInteger f = [[self.rView subviews] indexOfObject:self.fView];
    NSUInteger z = [[self.rView subviews] indexOfObject:self.window];
    [self.rView exchangeSubviewAtIndex:z withSubviewAtIndex:f];
    
//    [[self.rView layer] addAnimation:animation forKey:@"animation"];
    
    [self performSelector:@selector(ToUpSide) withObject:nil afterDelay:1];//1秒后执行TheAnimation
}
#pragma mark - 上升效果
- (void)ToUpSide {
    [self moveToUpSide];//向上拉界面
}

- (void)moveToUpSide {
    [UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionTransitionCurlUp animations:^{
        self.rView.frame = CGRectMake(self.window.frame.origin.x,
                                 -self.window.frame.size.height,
                                 self.window.frame.size.width,
                                 self.window.frame.size.height);
        
    } completion:^(BOOL finished) {
    }];
}

-(void)setZView:(UIImageView *)zView{
    objc_setAssociatedObject(self, &zViewKey, zView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(UIImageView *)zView{
    return objc_getAssociatedObject(self, &zViewKey);
}
-(void)setFView:(UIImageView *)fView{
    objc_setAssociatedObject(self, &fViewKey, fView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(UIImageView *)fView{
    return objc_getAssociatedObject(self, &fViewKey);
}
-(void)setRView:(UIImageView *)rView{
    objc_setAssociatedObject(self, &rViewKey, rView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(UIImageView *)rView{
    return objc_getAssociatedObject(self, &rViewKey);
}

@end
